package com.example.Listener;



import com.example.mapper.LogMapper;
import com.example.pojo.Logs;
import com.example.pojo.User;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.logging.LogManager;

/**
 * @version 1.0
 * @Author wql
 * @Date 2024/5/30
 * @Description
 */
@Component
public class RabbitListener1 {
    @Autowired
    private LogMapper logMapper;
    @RabbitListener(
            bindings = @QueueBinding(
                    value = @Queue(name = "logs.queue"),
                    exchange = @Exchange(name = "Register.exchange",type = ExchangeTypes.DIRECT),
                    key = ""
            )
    )
    public void listenSimpleQueueExDir2(User user) throws InterruptedException {
        Logs logs = new Logs();
        System.out.println("日志消费者接收到消息：【" + user + "】" + new Date());
        BeanUtils.copyProperties(user, logs,"id");
        logs.setUserId(user.getId());
        System.out.println(logs);
        logMapper.insert(logs);
    }
}
